import {loadEnv} from 'vite'
// import {IEnv} from '@/type/store/interface'
// import { GlobEnvConfig } from "#/confi";


export interface IEnv {
  // 端口
  VITE_PORT:string,
  // 项目路径(base path)
  VITE_PUBLIC_PATH:string,
  VITE_DROP_CONSOLE:string,
  VITE_BUILD_GZIP:string,
  VITE_USE_PWA:string,
  VITE_USE_CDN:string,
  VITE_PROXY:string,
  // 网站标题
  VITE_GLOB_APP_TITLE: string;
  
  VITE_GLOB_API_URL: string;
  VITE_GLOB_API_URL_PREFIX?: string;
  VITE_GLOB_APP_SHORT_NAME: string;
  // 是否mock
  VITE_USE_MOCK:string
}


/**
 *
 * @param mode 环境后缀 空| development | production
 * 
 */
export default (mode?: string) => {
  // console.log('mode',mode)
  if (!mode) {
    mode = ''
  }
  // console.log(process.argv)
  //获取本地环境文件
  let _env:IEnv = loadEnv(mode, process.cwd()) as any
  const env = {
    port: parseInt(_env.VITE_PORT),
    publicPath:_env.VITE_PUBLIC_PATH || '',
    dropConsole:_env.VITE_DROP_CONSOLE==='true',
    useGzip:_env.VITE_BUILD_GZIP==='true',
    usePwa:_env.VITE_USE_PWA==='true',
    useCdn:_env.VITE_USE_CDN==='true',
    useMock:_env.VITE_USE_MOCK==='true',
    proxy:_env.VITE_PROXY && JSON.parse(_env.VITE_PROXY),
    appTitle:_env.VITE_GLOB_APP_TITLE,
    apiUrl:_env.VITE_GLOB_API_URL,
    apiUrlPrefix:_env.VITE_GLOB_API_URL_PREFIX,
    shortName:_env.VITE_GLOB_APP_SHORT_NAME
  }
 
  return env;
}